<?php
// +----------------------------------------------------------------------
// | CLTPHP.Pro [后台登录]
// +----------------------------------------------------------------------
// | Copyright (c) 2019-2029 https://www.cltphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://www.cltphp.com/detail-140.html )
// +----------------------------------------------------------------------
// | Author: chichu <1109305987@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\model\Admin;
use app\common\model\System;
use think\captcha\facade\Captcha;
use think\facade\View;

class Login
{
    private $system;

    public function __construct()
    {
        //查找所有系统设置表数据
        $info = System::getListField()->toArray();
        //格式化设置字段
        $info = sysgem_setup($info);
        foreach ($info as $k => $v) {
            $this->system[$v['field']] = $v['value'];
        }
        cache('system', $this->system);
    }

    // 登录页面
    public function index()
    {
        View::assign('system', $this->system);
        return View::fetch();
    }

    //登录
    public function login()
    {
        return Admin::login($this->system['code']);
    }

    //验证码
    public function captcha()
    {
        return Captcha::create();
    }

    // 退出登录
    public function logout()
    {
        session('admin', null);
        return ['code' => 0, 'msg' => '退出成功!'];
    }

}